﻿using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class LoadingBar : MonoBehaviour
{
    public static string sceneName;
    //异步对象
    AsyncOperation async;
    // Use this for initialization
    void Start()
    {
        //GetComponent<Slider>().onValueChanged.AddListener(OnValueChanged);
        //if (sceneName != null)
        //    StartCoroutine(LoadSceneInner());
    }

    public void OnValueChanged(float progress)
    {
        GetComponent<Slider>().value = progress;
    }
    // Update is called once per frame
    void Update()
    {
        //float progress = (int)(async.progress * 100);
    }

    //注意这里返回值一定是 IEnumerator
    IEnumerator LoadSceneInner()
    {
        //异步读取场景。
        //Globe.loadName 就是A场景中需要读取的C场景名称。
        async = Application.LoadLevelAsync(sceneName);

        //读取完毕后返回， 系统会自动进入C场景
        yield return async;

    }
    void OnDestroy()
    {
        sceneName = null;
    }

}
